package cn.huanzi.qch.baseadmin.travel.scenic.service;


import cn.huanzi.qch.baseadmin.common.service.CommonServiceImpl;
import cn.huanzi.qch.baseadmin.travel.scenic.pojo.Scenic;
import cn.huanzi.qch.baseadmin.travel.scenic.repository.ScenicRepository;
import cn.huanzi.qch.baseadmin.travel.scenic.vo.ScenicVo;
import cn.huanzi.qch.baseadmin.travel.thotel.pojo.THotel;
import cn.huanzi.qch.baseadmin.travel.thotel.vo.THotelVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class ScenicServiceImpl extends CommonServiceImpl<ScenicVo, Scenic, Integer> implements ScenicService{

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ScenicRepository scenicRepository;

    @Override
    public List<ScenicVo> findAll() {
        List<Scenic> allScenic = scenicRepository.findAll();
        ArrayList<ScenicVo> sciences = new ArrayList<>();
        for (Scenic scenic : allScenic) {
            ScenicVo scenicVo = new ScenicVo();
            BeanUtils.copyProperties(scenic, scenicVo);
            sciences.add(scenicVo);
        }
        return sciences;
    }

    @Override
    public Scenic findByScenicID(Integer id) {
        Optional<Scenic> scenicById = scenicRepository.findById(id);
        return scenicById.get();
    }
}
